﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Collections;
namespace TS_XY_Train_Repaire.UserCon.Stuff
{
    public partial class uc_Stuff_GangWei_ManaForm : DevExpress.XtraEditors.XtraForm
    {
        public uc_Stuff_GangWei_ManaForm()
        {
            InitializeComponent();
        }

        private void uc_Stuff_GangWei_ManaForm_Load(object sender, EventArgs e)
        {
            _Loadtl_Main();
        }
        private void _Loadtl_Main()
        {
            LeverString_SysOrganization _ls = new LeverString_SysOrganization();
            tl_Main.Nodes.Clear();
            tl_Main.Refresh();
            ArrayList pList = new ArrayList();
            string strSQL = "select * from TS_S_T_P_StationBiaoShi  where f_del=0";
            SqlConnection conn = new SqlConnection(TS_Win_Class.GetSQlConnStr());
            conn.Open();
            SqlCommand cmd = new SqlCommand(strSQL, conn);
            SqlDataReader read = cmd.ExecuteReader();
            while (read.Read())
            {
                _ls = new LeverString_SysOrganization();
                _ls.f_id = read["f_id"].ToString();
                _ls.f_name = read["f_name"].ToString();
                pList.Add(_ls);
            }
            read.Close();
            conn.Close();
            conn.Dispose();

            tl_Main.DataSource = pList;
        }
        private void bt_Add_Click(object sender, EventArgs e)
        {
            string strSQL = "insert into TS_S_T_P_StationBiaoShi(f_name,f_workerid) values('" + tb_Name.Text.Trim() + "'," + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ") ";
            TS_Win_Class.MySqlCom(strSQL);
            _Loadtl_Main();
        }

        private void bt_Edit_Click(object sender, EventArgs e)
        {
            string strSQL = "update TS_S_T_P_StationBiaoShi set f_name='" + tb_Name.Text.Trim() + "',f_workerid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time=getdate() where f_id=" + tl_Main.FocusedNode["f_id"].ToString();
            TS_Win_Class.MySqlCom(strSQL);
            _Loadtl_Main();
        }

        private void bt_Del_Click(object sender, EventArgs e)
        {
            string strSQL = "update TS_S_T_P_StationBiaoShi set f_del=1,f_workerid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time=getdate() where f_id=" + tl_Main.FocusedNode["f_id"].ToString();
            TS_Win_Class.MySqlCom(strSQL);
            _Loadtl_Main();
        }

        private void bt_Exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void tb_Name_TextChanged(object sender, EventArgs e)
        {
            bt_Add.Enabled = false;
            bt_Edit.Enabled = false;
            bt_Del.Enabled = false;
            if (tb_Name.Text.Trim().Length > 0)
            {
                bt_Add.Enabled = true;
                if (tl_Main.Nodes.Count > 0)
                {
                    bt_Edit.Enabled = true;
                    bt_Del.Enabled = true;
                }
            }
        }

        private void tl_Main_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
        {
            try
            {
                tb_Name.Text = tl_Main.FocusedNode["f_name"].ToString();
            }
            catch
            {
                tb_Name.Text = "";
            }
        }
    }
}